﻿using PlutoStudio.Dependency;
using PlutoStudio.Web.Security.AntiForgery;
using System;
using System.Collections.Generic;
using System.Text;

namespace PlutoStudio.Web.Security
{
    internal class SecurityScriptManager : ISecurityScriptManager, ITransientDependency
    {
        private readonly IAntiForgeryConfiguration _plutostudioAntiForgeryConfiguration;

        public SecurityScriptManager(IAntiForgeryConfiguration plutostudioAntiForgeryConfiguration)
        {
            _plutostudioAntiForgeryConfiguration = plutostudioAntiForgeryConfiguration;
        }

        public string GetScript()
        {
            var script = new StringBuilder();

            script.AppendLine("(function(){");
            script.AppendLine("    plutostudio.security.antiForgery.tokenCookieName = '" + _plutostudioAntiForgeryConfiguration.TokenCookieName + "';");
            script.AppendLine("    plutostudio.security.antiForgery.tokenHeaderName = '" + _plutostudioAntiForgeryConfiguration.TokenHeaderName + "';");
            script.Append("})();");

            return script.ToString();
        }
    }
}
